<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
  <!--   <title>大连大学附属中山医院</title> -->
    <script type="text/javascript" src="${basePath}/static/publics/assets/jqPaginator/jqPaginator.js"></script>
	<script type="text/javascript" src="${basePath}/static/publics/assets/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
	<div class="list_NR">
        <div class="loc">
            <h3>病案可发行</h3>
          
        </div>
        
        <div class="list_con_table">
         <input type="hidden" value="${medTraceQuery.totalCounts }" id="totalCountsHidden">
			 <form action="${basePath}/statis/queryMedShelveByAjax" method="get" id="queryForm">
	        	<input type="hidden" name="currentPage" value="${medTraceQuery.currentPage }" id="currentPageHidden">
	        	<input type="hidden" name="pageSize" value="${medTraceQuery.pageSize }" id="pageSizeHidden">
	        	<div class="search_table">
                <ul class="clearfix" style="margin-bottom:0;">
                 <li class="Label_1" style="width:10%">ID号：&nbsp;</li>
				    <li class="Label_2" style="width:18%"><input class="input_box" type="text" name='mrId' id="mrId" value='${medTraceQuery.mrId}' /></li>
                 
					<li class="Label_1" style="width:11%">住院次数：&nbsp;</li>
				    <li class="Label_2" style="width:22%"><input class="input_box"  type="text" id="visitNumber" name='visitNumber' value='${medTraceQuery.visitNumber}' /></li>
				 	<li class="Label_1" style="width:11%">出院日期：&nbsp;</li>
                    <li class="Label_2" style="width:28%">
                    	<input class="input_box" style="width:42%;" type="text" name="outHospitalStartDate" value='<fmt:formatDate value="${medTraceQuery.outHospitalStartDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" />
                    	<span>-</span>
                    	<input class="input_box" type="text" style="width:42%;" name="outHospitalEndDate" value='<fmt:formatDate value="${medTraceQuery.outHospitalEndDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" />
                    </li>
				   <li class="Label_1" style="width:10%">身份证号：&nbsp;</li>
				    <li class="Label_2" style="width:18%"><input class="input_box"  type="text"  name='idCard' value='${medTraceQuery.idCard}' /></li>
				   <li class="Label_1" style="width:11%">发行状态：&nbsp;</li>
				    <li class="Label_2" style="width:22%">
				    
				    	<c:choose>
				    		<c:when test="${medTraceQuery.traceTypeId!=null}">
				    				 <input type="radio"  name='traceTypeId' <c:if test="${medTraceQuery.traceTypeId==2}">checked="checked"</c:if> value='2' />未发行&nbsp;&nbsp;
    					 			<input type="radio"  name='traceTypeId' <c:if test="${medTraceQuery.traceTypeId==7}">checked="checked"</c:if> value='7' />已发行
				    		</c:when>
				    		<c:otherwise>
				    				<input  type="radio"  name='traceTypeId' checked="checked" value='2' />未发行&nbsp;&nbsp;
    					 			<input  type="radio"  name='traceTypeId' checked="checked" value='7' />可发行
				    		</c:otherwise>
				    	</c:choose>
				    </li>
				   	<input type="hidden" name="orderType" id='orderType' value="${medTraceQuery.orderType}">
                   <li class="Label_1" style="width:11%">出院科室：&nbsp;</li>
				    <li class="Label_2" style="width:28%">
				    	<select name="outHospitalOfficeId" class="input_box">
				    		<option value="">请选择</option>
				    		<c:forEach var="outOffice" items="${offices }">
				    			<c:choose>
				    				<c:when test="${ medTraceQuery.outHospitalOfficeId==outOffice.id}">
				    					<option value="${outOffice.id }" selected="selected">${outOffice.name }</option>
				    				</c:when>
				    				<c:otherwise>
				    					<option value="${outOffice.id }">${outOffice.name }</option>
				    				</c:otherwise>
				    			</c:choose>
				    		</c:forEach>
				    	</select>
				    </li>
				  <%--   <li class="Label_1" style="width:10%;">上架单号：&nbsp;</li>
				    <li class="Label_2" style="width:30%"><input class="input_box"  type="text"  name='mrId' value='${medTraceQuery.mrId}' /></li> --%>
				 	   
                    <li class="Label_5">
                        <div class="right" style="text-align:right">
                            <a id="Add" onclick="queryFormSubmit()">查询</a>
                            
                             <a id="Add" onclick="selectPublish()">选中发行</a>
                        </div>
                    </li>
                </ul>
            </div>
	        </form>

        </div>
       
        <table class="Search_tableList" cellpadding="0" cellspacing="0">
     
            <tr>
            	
            	<td class="tdLabel_4"><input type="checkbox" id="checkAll" name="publish" /></td>
                <td class="tdLabel_4">姓名</td>
                <td class="tdLabel_4">身份证号</td>
                <td class="tdLabel_4">ID号</td>
                 <td class="tdLabel_4"><a class="int" onclick="orderByType(this)" data-order-type="${medTraceQuery.orderType}">住院次数</a></td>
                 <td class="tdLabel_4">出院科室</td>
                <td class="tdLabel_4">出院日期</td>
                <!-- <td class="tdLabel_4">记录日期</td> -->
                <td class="tdLabel_4">操作</td>
            </tr>
            
            <tr id="loading" style="height:50px;display:none">
	             <td colspan="7" align="center" ><img src="${basePath}/static/image/loading-2.gif"></td>
	   		 </tr>
            <tbody id="tbody">
            	<c:forEach var="treatmentTrace" items="${treatmentTraces }">
            		<tr data-guid="${treatmentTrace.treatment_guid }">
            			
            			<td class='tdLabel_5'>${treatmentTrace.isPage==1?'':'<input type="checkbox" class="publish"  name="publish" />'}</td>
            			<td class='tdLabel_5'>${treatmentTrace.patient_name}</td>
            			<td class='tdLabel_5'>${treatmentTrace.id_cards}</td>
            			<td class='tdLabel_5'>${treatmentTrace.mr_id}</td>
            			<td class='tdLabel_5'>${treatmentTrace.visit_number}</td>
            			<td class='tdLabel_5'>${treatmentTrace.outOfficeName}</td>
            			<td class='tdLabel_5'><fmt:formatDate value="${treatmentTrace.out_hospital_date}" pattern="yyyy-MM-dd"/></td>
            			<%-- <td class='tdLabel_5'><fmt:formatDate value="${treatmentTrace.trace_date}" pattern="yyyy-MM-dd"/></td>
            			 --%>
            			 <td class='tdLabel_5'>
            				<c:choose>
            					<c:when test="${treatmentTrace.isPublish==1}">
            							<a class="int" onclick='putOnShelve("${treatmentTrace.treatment_guid}",this)'>许可发行</a>
            					</c:when>
            					<c:otherwise>
            						<a>已发行</a>
            					</c:otherwise>
            				</c:choose>
            			</td>
            			
            		</tr>
            	</c:forEach>
            </tbody>
               
           
        </table>
        <div class="pageList">
            <ul class="pagination clearfix" id="page_plus"></ul>
            <div class="pagination">
                <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
            </div>
        </div>
        
         <form action="${basePath}/statis/queryMedShelveByAjax" method="get" id="pageForm">
	        	<input type="hidden" name="currentPage" value="${medTraceQuery.currentPage }" id="currentPageHid">
	        	<input type="hidden" name="pageSize" value="${medTraceQuery.pageSize }" id="pageSizeHid">
	        	<input type="hidden" name="name" value="${medTraceQuery.name }">
	        	<input type="hidden" name="mrId" value="${medTraceQuery.mrId }">
	        	<input type="hidden" name="visitNumber" value="${medTraceQuery.visitNumber }">
	        	<input type="hidden" name="idCard" value="${medTraceQuery.idCard }">
	        	<input type="hidden" name="outHospitalStartDate" value="<fmt:formatDate value="${medTraceQuery.outHospitalStartDate}" pattern="yyyy-MM-dd"/>">
	        	<input type="hidden" name="outHospitalEndDate" value="<fmt:formatDate value="${medTraceQuery.outHospitalEndDate}" pattern="yyyy-MM-dd"/>">
	        	<input type="hidden" name="outHospitalOfficeId" value="${medTraceQuery.outHospitalOfficeId}">
	        	<input type="hidden"  name='traceTypeId' value="${medTraceQuery.traceTypeId}" />
	        	<input type="hidden" name="status" value="7">
	        	<input type="hidden" name="orderType" id='hiddenOrderType' value="${medTraceQuery.orderType}">
	        </form> 
    </div>
</body>

<script type="text/javascript">
function queryFormSubmit(){
	$("#currentPageHidden").val(1);
	$("#queryForm").submit();
}


//选择所有或取消选择所有
$("#checkAll").click(function() {
	if ($(this).is(":checked")) {
		$(".publish").each(function(index) {
			$(this).prop("checked", true);
		});
	} else {
		$(".publish").each(function(index) {
			$(this).prop("checked", false);
		});
	}
});

$("#mrId").change(function(){
	var $this=$(this);
	var inentity=$this.val();
	if(inentity!=null && inentity!='' && inentity!=undefined){
		if(isContainMark(inentity)){
			var mrId=inentity.split("-")[0];
			var visitNumber=inentity.split("-")[1];
			
			if(!isNumber(visitNumber)){
				alert("请重新扫描条形码");
				$("#mrId").val("").focus();
				$("#visitNumber").val("");
				
				return;
			}
			//alert(mrId+"--"+visitNumber);
			$("#mrId").val("").val(mrId);
			$("#visitNumber").val("").val(visitNumber);
			$("#queryForm").submit();
		}
	}
});

function selectPublish(){
	var guidArr =[];
	$(".publish:checked").each(function(index) {
		//alert($(this).parents("tr").attr("data-guid"));
		guidArr.push($(this).parents("tr").attr("data-guid"));
	});
	if(guidArr==null || guidArr.length==0){
		layer.alert('请选择要发行的病案!',{icon:1});
		return;
	}
	$("#loading").show();
	$.ajax({
		type:"post",
		data:{guids:guidArr.toString()},
		url:"${basePath}/statis/medPutOnShelveList",
		success:function(data){
			if(data.success){
				$("#loading").hide();
				layer.alert("病案许可发行!",{icon:1});
				
				$("#queryForm").submit();
			}else{
				$("#loading").hide();
				layer.alert("病案发行失败!",{icon:1});
			}
		}
	});
	
}


function orderByType(obj){
	var $this = $(obj);
	var orderType = $this.attr("data-order-type");
	orderType=orderType=="asc"?"desc":"asc";
	$("#hiddenOrderType").val(orderType);
	$("#orderType").val(orderType);
	$this.attr("data-order-type",orderType);
	$("#queryForm").submit();
	
}


function isNumber(value) {
    var patrn = /^[0-9]*$/;
    if (patrn.exec(value) == null || value == "") {
        return false
    } else {
        return true
    }
}


function isContainMark(inentity){
	var reg = RegExp(/-/);
	return reg.test(inentity);
}


$(function(){
	$("#mrId").focus();
	var totalCounts = $("#totalCountsHidden").val();
	var pageSize = $("#pageSizeHidden").val();
	var currentPage = $("#currentPageHidden").val();
	initPage(parseInt(totalCounts),parseInt(pageSize),parseInt(currentPage));
});

function initPage(totalCounts,pageSize,currentPage){
	 var visiblePages = 5;
	 var totalPages =  totalCounts%pageSize==0?(totalCounts/pageSize):(parseInt(totalCounts/pageSize)+1);
	 $('#page_plus').jqPaginator({

	        totalCounts: totalCounts,
	        pageSize:pageSize,
	        visiblePages: visiblePages,
	        currentPage: currentPage,

	        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
	        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
	        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
	        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
	        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
	        onPageChange: function (num,type) {

	     		if(type !='init'){
	     			$("#currentPageHidden").val(num);
					$("#pageSizeHidden").val(pageSize);
					$("#currentPageHid").val(num);
					$("#pageSizeHid").val(pageSize);
					$("#pageForm").submit();
				}
	            $("#totalPage").html(totalCounts);
	            $("#currentPage").html(num+"/"+totalPages);
	            $("#currentPageHidden").val(currentPage);
			    $("#pageSizeHidden").val(pageSize);
	        }
	    });

}
//病案发行
function putOnShelve(guid,obj){
	$("#loading").show();
	$.ajax({
		type:"post",
		async:false,
		url:"${basePath}/statis/medPutOnShelve",
		data:{guid:guid},
		/* beforeSend:function(){
	 		$("#loading").show();
	 	}, */
		success:function(result){
			if(result!=null){
				if(result.success){
					layer.alert("病案许可发行!",{icon:1});
					$(obj).html("已发行");
					$(obj).removeClass("int");
					$("#loading").hide();
					//$("#queryForm").submit();
				} else{
					layer.alert(result.msg,{icon:0});
					$("#loading").hide();
				}
				//layer.alert(result.msg,{icon:1});
			//	layer.alert("请选择要上传的文件夹！", {icon: 0});
			}else{
				//alert();
				layer.alert("病案发行失败",{icon:0});
				$("#loading").hide();
			}
		}
	});
}
</script>





